<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/Lib/Base.php';
require_once __DIR__ . '/funcs.php';
require_once __DIR__ . '/Lib/Page.php';

checkLogin();

// 权限检查
$funcs = getFuncs($_SESSION['admin_group']);
checkFunc(9900);

$now = time();
$success = $_GET['success'] ?? null;
$error = $_GET['error'] ?? null;
$action = $_GET['action'] ?? null;

$groups = [];
$all_group = $DB->select('admin_groups', '*');
foreach($all_group as $gp) {
	$groups[$gp['id']] = $gp;
}
$group_json = json_encode($groups);

if($action) {
	if ($action == 'change_group') {
		$admin_id = $_GET['admin_id'] ?? null;
		if ($admin_id == 1) $admin_id = null;
		$new_group = $_GET['new_group'] ?? null;
		$old_gropu_id = $_GET['old_group_id'] ?? null;
		if (!$admin_id || !$new_group) {
			$error = '无效的新分组ID';
		} else {
		    $DB->update('admin_user', ['groupid'=>$new_group], ['id'=>$admin_id]);
			$success = '分组修改成功';
			operate_log('super', 'change_group', ['管理员ID' => $admin_id, '旧组ID' => $old_gropu_id, '新组ID' => $new_group]);
		}
	} else if($action == 'change_pass') {
		$aid = $_GET['aid'] ?? null;
		if($aid == 1) $admin_id = null;
		if (!$aid) {
			$error = '无效的管理员账号ID';
		} else {
		    $new_pass = $_GET['new_pass'] ?? null;
		    $new_pass = trim($new_pass);
			if (!$new_pass) {
				$error = '新密码不可为空';
			} else {
			    $DB->update('admin_user', ['pass'=>md5(md5($new_pass)), 'pass_str'=>$new_pass], ['id'=>$aid]);
				$success = '密码修改成功';
				operate_log('super', 'change_pass', ['管理员ID'=>$aid]);
            }
        }
	} else if ($action == 'freeze') {
		$aid = $_GET['aid'] ?? null;
		if($aid == 1) $admin_id = null;
		if (!$aid) {
			$error = '无效的管理员账号ID';
		} else {
            $DB->update('admin_user', ['status'=>0], ['id'=>$aid]);
			$success = '冻结成功';
			operate_log('super', 'freeze', ['管理员ID'=>$aid]);
		}
	} else if ($action == 'unfreeze') {
		$aid = $_GET['aid'] ?? null;
		if($aid == 1) $admin_id = null;
		if (!$aid) {
			$error = '无效的管理员账号ID';
		} else {
            $DB->update('admin_user', ['status'=>1], ['id'=>$aid]);
			$success = '解冻成功';
			operate_log('super', 'un_freeze', ['管理员ID'=>$aid]);
		}
	} else if ($action == 'delete') {
		$aid = $_GET['aid'] ?? null;
		if($aid == 1) $admin_id = null;
		if (!$aid) {
			$error = '无效的管理员账号ID';
		} else {
		    $DB->delete('admin_user', ['id'=>$aid]);
			$success = '删除成功';
			operate_log('super', 'delete', ['管理员ID'=>$aid]);
		}
	} else if($action == 'change_funcs') {
		$aid = $_GET['admin_id'] ?? null;
		if($aid == 1) $admin_id = null;
		if (!$aid) {
			$error = '无效的管理员账号ID';
		} else {
		    $old_info = $DB->get('admin_user', ['groupid','funcs'], ['id'=>$aid]);
		    $new_group = $_GET['new_group'] ?? null;
		    $all_funcs = $_GET['all_funcs'] ?? '';
			$orig_funcs = explode(',', $groups[$new_group]['funcs']);
			$submit_funcs = explode(',', $all_funcs);
			$extra_funcs = [];
			if (empty($submit_funcs)) {
				foreach ($orig_funcs as $of) {
					$extra_funcs[] = -$of;
				}
			}
			foreach ($orig_funcs as $of) {
				if (!in_array($of, $submit_funcs)) {
					$extra_funcs[] = -$of;
				}
			}
			foreach ($submit_funcs as $sf) {
				if (!in_array($sf, $orig_funcs)) {
					$extra_funcs[] = $sf;
				}
			}
			$extra_funcs_str = join(',', $extra_funcs);
			try {
                $DB->update('admin_user', [
                    'groupid' => $new_group,
                    'funcs' => $extra_funcs_str
                ], ['id'=>$aid]);
				$success = '权限修改成功';
				operate_log('super', 'change_funcs', [
				    '管理员ID'=>$aid,
                    '旧组ID'=>$old_info['groupid'],
                    '新组ID' => $new_group,
                    '旧额外权限' => $old_info['funcs'],
                    '新额外权限' => $extra_funcs_str,
                ]);
			} catch(\Exception $e) {
				$error = '权限修改失败'; //<br />详细报错:<br />' . $e->getMessage();
			}
		}
	} else if ($action == 'new_admin') {
		$gpid = $_GET['groupid'] ?? null;
		$uname = $_GET['username'] ?? null;
		$pswd = $_GET['password'] ?? null;
		$fs = $_GET['funcs'] ?? [];
		if (!$gpid || !$uname || !$pswd || !isset($groups[$gpid])) {
			$error = '数据不完整,创建失败';
		} else {
			$orig_funcs = explode(',', $groups[$gpid]['funcs']);
			$submit_funcs = explode(',', $fs);
			$extra_funcs = [];
			if (empty($submit_funcs)) {
				foreach ($orig_funcs as $of) {
					$extra_funcs[] = -$of;
				}
			}
			foreach ($orig_funcs as $of) {
				if (!in_array($of, $submit_funcs)) {
					$extra_funcs[] = -$of;
				}
			}
			foreach ($submit_funcs as $sf) {
				if (!in_array($sf, $orig_funcs)) {
					$extra_funcs[] = $sf;
				}
			}
			$extra_funcs_str = join(',', $extra_funcs);
			try {
				$DB->insert('admin_user', [
					'groupid' => $gpid,
					'username' => $uname,
					'pass' => md5(md5($pswd)),
					'pass_str' => $pswd,
					'create_time' => $now,
					'status' => 1,
					'funcs' => $extra_funcs_str
				]);
                $new_uid = $DB->id();
				if ($new_uid > 0) {
					$success = '创建成功';
					operate_log('super', 'new_user', ['管理员ID' => $new_uid, '组ID' => $gpid, '账号' => $uname, '组内权限' => $groups[$gpid]['funcs'], '额外权限' => $extra_funcs_str]);
				} else $error = '创建账号失败';
			} catch(\Exception $e) {
			    $error = '帐号名重复,创建失败'; //<br />详细报错:<br />' . $e->getMessage();
            }
		}
	}
	else {
        $error = '无效的操作';
	}
	goExit('super_user.php?success=' . $success . '&error=' . $error);
}

$all_admin = $DB->select('admin_user', '*', ['ORDER'=>['id'=>'DESC']]);

$all_funcs = [];
$func_ids = [];
$get_funcs = $DB->select('admin_funcs', '*');
foreach($get_funcs as $func) {
    $desc_arr = explode('-', $func['desc']);
    $all_funcs[$desc_arr[0]][$desc_arr[1]][$desc_arr[2]] = $func['id'];
    $func_ids[] = $func['id'];
}

display_header();
?>

<style>
    .data_table th {font-size:14px; color:#666; font-weight:normal; width:180px;}
    .data_table td {font-size:18px; font-weight:normal;text-align:right;}
    .data_table td small {font-size:12px; color:#888;margin-left:3px;}
    .data_table td div {padding:0;}
    td,th {vertical-align:middle !important;}
    .filter_box span {border:1px solid #4b97c4; border-radius:5px; padding:4px 7px; margin-right:10px;}
    .modal_table_style td {font-size:16px;}
    .funcs_box {}
    .funcs_box label {font-weight:normal;}
    .funcs_box input {margin:0; padding:0;}
</style>


<section class="content">

	<?php if($error) : ?>
        <div class="alert alert-warning alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
			<span><?php echo $error; ?></span>
        </div>
	<?php endif ?>
	<?php if($success) : ?>
        <div class="alert alert-success alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon fa fa-check"></i> 成功</h4>
			<?php echo $success; ?>
        </div>
	<?php endif ?>

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title"><i class="fa fa-search"></i> 管理员列表</h3>
        </div>

        <div class="box-body" id="vbody">

            <button type="button" class="btn btn-primary pull-left" style="margin-bottom:10px;" data-toggle="modal" data-target="#modal-add-admin">添加管理员账号</button>

            <table id="logtable" class="table table-bordered table-striped dataTable table-hover " role="grid" aria-describedby="example1_info">
                <thead>
                <tr>
                    <th class="" rowspan="1" colspan="1" width="50" style="text-align:center">ID</th>
                    <th class="" rowspan="1" colspan="1" width="50" style="text-align:center;">组ID</th>
                    <th class="" rowspan="1" colspan="1" width="80" style="text-align:center;">组名</th>
                    <th class="" rowspan="1" colspan="1" width="200">账号名</th>
                    <th class="" rowspan="1" colspan="1" width="130" style="text-align:center">创建时间</th>
                    <th class="" rowspan="1" colspan="1" width="80" style="text-align:center">登录次数</th>
                    <th class="" rowspan="1" colspan="1" width="130" style="text-align:center">最后登录时间</th>
                    <th class="" rowspan="1" colspan="1" width="90" style="text-align:center">最后登录IP</th>
                    <th class="" rowspan="1" colspan="1" width="100" style="text-align:center">账号状态</th>
                    <th class="" rowspan="1" colspan="1" style="text-align:center">操作</th>
                </tr>
                </thead>
                <tbody>
				<?php if(!empty($all_admin)) { foreach($all_admin as $admin) { ?>
                    <tr role="row" style="text-align:center;">
                        <td><?php echo $admin['id']; ?></td>
                        <td><?php echo $admin['groupid']; ?></td>
                        <td style="font-size:12px;"><?php echo $groups[$admin['groupid']]['name']; ?></td>
                        <td style="text-align:left;font-size:16px;"><?php echo $admin['username']; ?></td>
                        <td style="font-size:10px;"><?php echo date('Y-m-d H:i:s', $admin['create_time']); ?></td>
                        <td><?php echo $admin['login_times']; ?></td>
                        <td style="font-size:10px;"><?php echo $admin['last_login'] ? date('Y-m-d H:i:s', $admin['last_login']) : '-'; ?></td>
                        <td style="font-size:10px;"><?php echo $admin['last_ip']    ? long2ip($admin['last_ip'])                    : '-'; ?></td>
                        <td><?php echo $admin['status']==1 ? '正常' : '<span style="color:#f00;">冻结</span>'; ?></td>
                        <td style="text-align:left;">
	                        <?php if($admin['id'] != 1) { ?>
                                <button type="button" class="btn btn-sm btn-success"
                                        data-toggle="modal" data-target="#modal-change-funcs"
                                        v-on:click="openModal('<?=$admin['id']?>', '<?=$admin['groupid']?>', '<?=$admin['username']?>', '<?=$admin['funcs']?>')"
                                >修改权限</button> |
                                <button type="button" class="btn btn-sm btn-info pulloff_notice" data-toggle="modal" data-target="#modal-change-password"
                                        v-on:click="setChangePassword('<?=$admin['id']?>')"
                                >修改密码</button> |
		                        <?php if($admin['status'] == 1) { ?>
                                    <button type="button" class="btn btn-sm btn-warning pulloff_notice" v-on:click="freeze('<?=$admin['id']?>')">冻结账号</button> |
		                        <?php } else { ?>
                                    <button type="button" class="btn btn-sm btn-success pulloff_notice" v-on:click="unFreeze('<?=$admin['id']?>')">解冻账号</button> |
		                        <?php } ?>
                                <button type="button" class="btn btn-sm btn-danger del_notice" v-on:click="delaccount('<?=$admin['id']?>')">删除账号</button>
	                        <?php } ?>
                        </td>
                    </tr>
				<?php } } ?>
                </tbody>
            </table>

            <!-- 添加管理员账号弹框 -->
            <div class="modal fade" id="modal-add-admin">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">添加管理员账号</h4>
                        </div>
                        <div class="modal-body">
                            <table border="0" width="100%" class="modal_table_style">
                                <tr height="45">
                                    <th width="150" style="text-align:right;padding-right:10px;">所属分组:</th>
                                    <td>
                                        <select id="change-group-newgroupid" class="form-control" v-on:change="new_change_group" v-model="new_groupid" style="width:100%;">
                                            <option value=""></option>
									        <?php foreach($groups as $group) : ?>
                                                <option value="<?php echo $group['id']; ?>"><?php echo $group['id'] . ' - ' . $group['name']; ?></option>
									        <?php endforeach; ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr height="45">
                                    <th style="text-align:right;padding-right:10px;">帐号名:</th>
                                    <td><input type="text" class="form-control" size="20" v-model="new_user_name" /></td>
                                </tr>
                                <tr height="45">
                                    <th style="text-align:right;padding-right:10px;">密码:</th>
                                    <td><input type="text" class="form-control" size="20" v-model="new_password" /></td>
                                </tr>
                                <tr height="45">
                                    <th style="text-align:right;padding-right:10px;">组内权限:<br /><span style="font-size:12px;color:#999;">可额外选择权限<br />也可取消组内默认权限</span></th>
                                    <td style="font-size:12px;">
                                        <div class="funcs_box" style="overflow-y:scroll;height:300px;padding:5px 10px; margin:10px 0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;border-left:1px solid #ccc;">
                                        <?php
                                        foreach($all_funcs as $cate_1 => $f) {
                                            echo '<div style="font-size:14px;font-weight:bold;margin-bottom:1px;">' . $cate_1 . '</div>';
                                            foreach($f as $cate_2 => $ff) {
                                                echo '<div style="border-bottom:1px solid #eee;margin:0;padding:0;margin-bottom:1px;">';
	                                            echo '<div style="width:150px;" class="pull-left">　　|—　' . $cate_2 . '</div>';
	                                            echo '<div class="pull-left">';
	                                            foreach($ff as $cate_3 => $fff) {
		                                            echo '<label style="margin-right:15px;display:inline-block;">';
		                                            echo '<input type="checkbox" class="minimal" v-model="new_current_group_funcs" value="'.$fff.'"> ';
		                                            echo $cate_3;
		                                            echo '</label>';
	                                            }
	                                            echo '</div>';
	                                            echo '<div style="clear:both"></div>';
                                                echo '</div>';
                                            }
                                        }
                                        ?>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-primary" v-on:click="submitAddAdmin">确定</button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 修改密码弹框 -->
            <div class="modal fade" id="modal-change-password">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">修改密码</h4>
                        </div>
                        <div class="modal-body">
                            <table border="0" width="100%" class="modal_table_style">
                                <tr height="35"><th width="90" style="text-align:left;">新密码:</th>
                                    <td>
                                        <input type="text" class="form-control" size="20" v-model="change_password" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-primary" v-on:click="submitChangePassword()">确定</button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 修改权限弹框 -->
            <div class="modal fade" id="modal-change-funcs">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">修改权限</h4>
                        </div>
                        <div class="modal-body">
                            <table border="0" width="100%" class="modal_table_style">
                                <tr height="45"><th width="150" style="text-align:right;padding-right:10px;">帐号名:</th><td>{{ action_admin_name }}</td></tr>
                                <tr height="45">
                                    <th style="text-align:right;padding-right:10px;">所属分组:<br /><span style="font-size:12px;color:#999;">修改分组后<br />额外权限将重置</span></th>
                                    <td>
                                        <select id="change-group-newgroupid" class="form-control" v-on:change="change_funcs_group" v-model="change_group_id" style="width:100%;">
                                            <?php foreach($groups as $group) : ?>
                                            <option value="<?php echo $group['id']; ?>"><?php echo $group['id'] . ' - ' . $group['name']; ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr height="45"><th width="150" style="text-align:right;padding-right:10px;">是否默认组权限:</th>
                                    <td><span style="font-size:14px;" v-html="change_extra"></span></td></tr>
                                <tr height="45">
                                    <th style="text-align:right;padding-right:10px;">组内权限:<br /><span style="font-size:12px;color:#999;">可额外选择权限<br />也可取消组内默认权限</span></th>
                                    <td style="font-size:12px;">
                                        <div class="funcs_box" style="overflow-y:scroll;height:300px;padding:5px 10px; margin:10px 0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;border-left:1px solid #ccc;">
                                        <?php
                                        foreach($all_funcs as $cate_1 => $f) {
                                            echo '<div style="font-size:14px;font-weight:bold;margin-bottom:1px;">' . $cate_1 . '</div>';
                                            foreach($f as $cate_2 => $ff) {
                                                echo '<div style="border-bottom:1px solid #eee;margin:0;padding:0;margin-bottom:1px;">';
	                                            echo '<div style="width:150px;" class="pull-left">　　|—　' . $cate_2 . '</div>';
	                                            echo '<div class="pull-left">';
	                                            foreach($ff as $cate_3 => $fff) {
		                                            echo '<label style="margin-right:15px;display:inline-block;">';
		                                            echo '<input type="checkbox" class="minimal" v-model="change_funcs" value="'.$fff.'"> ';
		                                            echo $cate_3;
		                                            echo '</label>';
	                                            }
	                                            echo '</div>';
	                                            echo '<div style="clear:both"></div>';
                                                echo '</div>';
                                            }
                                        }
                                        ?>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-primary" v-on:click="submitChangeFuncs()">确定</button>
                        </div>
                    </div>
                </div>
            </div>

</section>

<!-- jQuery 3 -->
<script src="js/jquery.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/vue.min.js"></script>
<script src="js/pace.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Select2 -->
<script src="bower_components/select2/dist/js/select2.full.min.js"></script>
<!-- InputMask -->
<script src="plugins/input-mask/jquery.inputmask.js"></script>
<script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>

<script type="text/javascript">
    var app = new Vue({
        el: '#vbody',
        data: {
            // 全局
            group_data: $.parseJSON('<?php echo $group_json; ?>'),
            all_func_ids: $.parseJSON('<?php echo json_encode($func_ids); ?>'),

            // 新增管理员
            new_groupid: '',
            new_user_name: '',
            new_password: '',
            new_current_group_funcs: [],

            action_aid: '',
            action_admin_name: '',

            change_password: '',

            // 修改分组
            change_group_id: '',
            change_funcs: [],
            change_extra: ''
        },
        methods: {
            setChangePassword: function(aid) {
                this.action_aid = aid;
            },
            new_change_group: function(e) {
                if(this.new_groupid) {
                    this.new_current_group_funcs = this.group_data[this.new_groupid]['funcs'].split(',');
                }
            },
            submitAddAdmin: function() {
                if(!this.new_groupid) { alert('必须选择分组'); return false; }
                if(!this.new_user_name) { alert('账号名不可为空'); return false; }
                if(!this.new_password) { alert('密码不可为空'); return false; }
                var group_funcs = this.new_current_group_funcs.join(',');
                var go = false;
                if(group_funcs.length < 1) {
                    if(confirm('确认创建这个无任何权限的账号吗?')) {
                        go = true;
                    }
                } else go = true;
                if(go === true) {
                    location.href = 'super_user.php?action=new_admin&groupid=' + this.new_groupid + '&username='
                                    + this.new_user_name + '&password=' + this.new_password + '&funcs=' + group_funcs;
                }
            },
            freeze: function(aid) {
                if(confirm('确定要冻结该账号吗?')) {
                    location.href = 'super_user.php?action=freeze&aid='+aid;
                }
            },
            unFreeze: function(aid) {
                if(confirm('确定要解冻该账号吗?')) {
                    location.href = 'super_user.php?action=unfreeze&aid='+aid;
                }
            },
            delaccount: function(aid) {
                if(confirm('确定要删除该账号吗?')) {
                    location.href = 'super_user.php?action=delete&aid='+aid;
                }
            },
            submitChangePassword: function() {
                if(this.action_aid.length < 1) { alert('未指定操作用户'); return false; }
                if(this.change_password.length < 1) { alert('密码不可为空'); return false; }
                location.href = 'super_user.php?action=change_pass&aid='+this.action_aid+'&new_pass='+this.change_password;
            },
            openModal: function(aid, gid, username, extra) {
                this.action_aid         = aid;
                this.change_group_id    = gid;
                this.action_admin_name  = username;
                if(extra.length > 0) this.change_extra = '<span style="color:#f00;">是, 已配置额外的权限</span>'; else this.change_extra = '<span style="color:green">否</span>';
                var old_funcs_arr       = this.group_data[gid]['funcs'].split(',');
                var extra_funcs_arr     = extra.split(',');
                var merge_funcs_arr     = [];
                for(kk in old_funcs_arr) {
                    var need_del = false;
                    for(k in extra_funcs_arr) {
                        if(extra_funcs_arr[k] < 0 && Math.abs(extra_funcs_arr[k]) == old_funcs_arr[kk]) {
                            need_del = true;
                            break;
                        }
                    }
                    if(need_del === false) merge_funcs_arr.push(old_funcs_arr[kk]);
                }
                for(k in extra_funcs_arr) {
                    if(extra_funcs_arr[k] > 0) {
                        merge_funcs_arr.push(extra_funcs_arr[k]);
                    }
                }
                this.change_funcs = merge_funcs_arr;
            },
            change_funcs_group: function() {
                this.change_funcs = this.group_data[this.change_group_id]['funcs'].split(',');
            },
            submitChangeFuncs: function() {
                location.href = 'super_user.php?action=change_funcs&admin_id='+this.action_aid+'&new_group='+this.change_group_id+'&all_funcs='+this.change_funcs;
            }
        }
    });

    $('#modal-add-admin').on('hidden.bs.modal', function() {
        app.new_groupid = '';
        app.new_user_name = '';
        app.new_password = '';
        app.new_current_group_funcs = [];
    });
    $('#modal-change-password').on('hidden.bs.modal', function() {
        app.change_password = '';
        app.action_aid = '';
    });
    $('#modal-change-funcs').on('hidden.bs.modal', function() {
        app.action_aid = '';
        app.action_admin_name = '';
        app.change_group_id = '';
        app.change_extra = '';
        app.change_funcs = [];
    });

    $(function() {
        setTimeout(function() {
            $('.alert-success').fadeOut();
            if($('.alert-warning').find('span').html() && $('.alert-warning').find('span').html().length < 60) {
                $('.alert-warning').fadeOut();
            }
        }, 2000);
    });
</script>

</body>
</html>
